#! /bin/sh

# Source debconf library.
. /usr/share/debconf/confmodule
db_version 2.0

case "$1" in
	upgrade|install-upgrade)
		;;
	abort-upgrade)
		exit 0
		;;
esac

#
# See if we upgraded from < 2.5.5-3 and need to move config file
#
if ([ "$1" = upgrade ] && dpkg --compare-versions "$2" le '2.5.5-3' )
then
	if [ -e /etc/squid.conf ]
	then
		if [ ! -d /etc/squid ]
		then
			mkdir /etc/squid
		fi
		if [ -e /etc/squid/squid.conf ]
		then
			mv /etc/squid/squid.conf /etc/squid/squid.conf.dpkg-old
		fi
		mv /etc/squid.conf /etc/squid/squid.conf
		touch /etc/squid/conffile-moved
	fi
fi

#
# Add the "proxy" user/group to /etc/passwd if needed.
#

if ! grep -q "^proxy:" /etc/passwd
then
	#
	#	Let's hope that this works; if /var/spool/squid is
	#	already present this fails :(
	#
	adduser --system --home /var/spool/squid --group proxy
	#
	# Change the shell so that cron jobs will work.
	# (They run as root now, but you can never know).
	#
	chsh -s /bin/sh proxy
fi

exit 0
